﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
   public class GmTypeService
    {
        //新增
        public static bool AddGmType(GmType gt)
        {
            SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Gt_Name",gt.Gt_Name) };
            return DBHelper.Instance().ExcuteProcedure("up_AddGmType", para);
        }
        //删除
        public static bool DeleGmType(int id)
        {
            SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Gt_Id", id) };
            return DBHelper.Instance().ExcuteProcedure("up_DeleGmType", para);
        }
        //修改指定全部内容
        public static bool UpdaGmType(GmType gt)
        {
            SqlParameter[] para = new SqlParameter[] { new SqlParameter("@Gt_Id",gt.Gt_Id), new SqlParameter("@Gt_Name",gt.Gt_Name)};
            return DBHelper.Instance().ExcuteProcedure("up_UpdaGmType", para);
        }
        //查询所有信息
        public static List<GmType> SeleAllGmType()
        {
            List<GmType> item = new List<GmType>();
            string sql = string.Format("select * from GmType ");
            DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    GmType gt = new GmType();
                    gt.Gt_Id = Convert.ToInt32(dt.Rows[i]["Gt_Id"].ToString());
                    gt.Gt_Name = dt.Rows[i]["Gt_Name"].ToString();
                    item.Add(gt);
                }
            }
            return item;
        }
        //查指定定id信息
        public static List<GmType> SeleIdGmType(int id)
        {
            List<GmType> item = new List<GmType>();
            string sql = string.Format("select * from GmType where Gt_Id='{0}'",id);
            DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    GmType gt = new GmType();
                    gt.Gt_Id = Convert.ToInt32(dt.Rows[i]["Gt_Id"].ToString());
                    gt.Gt_Name = dt.Rows[i]["Gt_Name"].ToString();
                    item.Add(gt);
                }
            }
            return item;
        }

        //查指定定类型名称信息
        public static List<GmType> SelenameGmType(string name)
        {
            List<GmType> item = new List<GmType>();
            string sql = string.Format("select * from GmType where Gt_Name like '%{0}%'", name);
            DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    GmType gt = new GmType();
                    gt.Gt_Id = Convert.ToInt32(dt.Rows[i]["Gt_Id"].ToString());
                    gt.Gt_Name = dt.Rows[i]["Gt_Name"].ToString();
                    item.Add(gt);
                }
            }
            return item;
        }

       //查询图片bigj俊的
        public static List<Game> Ga_me(int Gm_TypeId)
        {
            string sql = "select top 6 * from Game where Gm_TypeId=" + Gm_TypeId;
            SqlDataReader di = DBHelper.Instance().GetDataReaderBySql(sql);
            List<Game> list = new List<Game>();
            while (di.Read())
            {
                Game p = new Game();
                p.Gm_Id = di.GetInt32(0);
                p.Gm_Name = di.GetString(1);
                p.Gm_TypeId = di.GetInt32(2);
                p.Gm_Price = Convert.ToDouble(di["Gm_Price"].ToString());
                p.Gm_Image = di.GetString(4);
                p.Gm_Lv = di.GetString(5);
                p.Gm_Desc = di.GetString(6);
                p.Gm_Upcount = di.GetInt32(7);

                list.Add(p);
            }
            di.Close();
            return list;
        }
    }
}
